<script setup lang="ts">
defineOptions({
  name: 'MicroAppContainer',
})

import { onMounted, onUnmounted } from 'vue'
import { useRoute } from 'vue-router'
import { useMicroAppsStore } from '@/stores/microApps'

const route = useRoute()
const microAppsStore = useMicroAppsStore()

// 监听微应用加载状态
onMounted(() => {
  // 设置初始状态
  microAppsStore.setLoading(true)
  microAppsStore.setError(null)

  // 这里可以添加微应用加载的自定义逻辑
  const timer = setTimeout(() => {
    microAppsStore.setLoading(false)
  }, 1000)

  onUnmounted(() => {
    clearTimeout(timer)
    microAppsStore.reset()
  })
})
</script>

<template>
  <div class="micro-app-container">
    <div v-show="!microAppsStore.loading && !microAppsStore.error" class="micro-app-wrapper">
      <!-- 微应用将被挂载到这个容器中 -->
    </div>

    <div v-show="!microAppsStore.loading && !microAppsStore.currentApp" class="no-app-message">
      <h2>欢迎使用微前端系统</h2>
      <p>请选择一个微应用来开始</p>
    </div>
  </div>
</template>

<style scoped>
.micro-app-container {
  height: 100%;
  min-height: 400px;
  padding: 1rem;
  background-color: #f8f9fa;
  border-radius: 8px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.micro-app-wrapper {
  height: 100%;
}

.no-app-message {
  text-align: center;
  padding: 3rem;
  color: #6c757d;
}

.no-app-message h2 {
  margin-bottom: 1rem;
  font-size: 1.5rem;
}

.no-app-message p {
  font-size: 1rem;
}

#micro-container {
  height: 100%;
  min-height: inherit;
}
</style>
